<?php
ob_start();
include_once './util/util.php';
$response = new stdClass();
$response->start = microtime(true);
try {
    if (!isset($_REQUEST['request']))
        throw new Exception("request is required", 1);
    $request = json_decode($_REQUEST['request']);
    $response->request = $request;

    if (!isset($request->type))
        throw new Exception("request->type is required", 1);

    $klass = ucfirst($request->type) . '_Frontend';
    $instance = new $klass();
    $response->response = $instance->getJSON($request);
} catch (Exception $ex) {
    $response->exception =  (string)$ex;
}
$response->end = microtime(true);
$response->info = ob_get_contents();
ob_clean();
echo json_encode($response)
?>
